home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 8
/
Night Owl CD-ROM (NOPV8) (Night Owl Publisher) (1993).ISO
/
047a
/
probots.arj
/
MARVIN.PR
< prev
next >
Wrap
Text File
|
1988-11-05
|
5KB
|
155 lines
PROCEDURE Marvin;
{ MARVIN - the not-so-paranoid robot }
{ Original C-Robot Created by:
Andrew Broding c/o the TASK Robot Development Factory }
VAR
degree : Integer; { degree for motion }
course : Integer; { degree for firing }
old_dam : Integer; { last damage check }
Range : Integer;
res : Integer;
srdegree : Integer;
PROCEDURE hitem; { hit a target }
VAR fdeg : Integer; { fire degree }
frange : Integer; { firing range }
index : Integer;
BEGIN
fdeg := course-5; { set resolution to +/- 5 }
index := 2;
WHILE (index > 0) AND (scan(fdeg, 5) = 0) DO
BEGIN
fdeg := fdeg+10;
index := index-1;
END;
frange := scan(fdeg, 5);
IF (frange > 0) THEN {didn't lose him }
BEGIN
IF (frange > 40) AND (frange < 800) THEN { good shooting range }
cannon(fdeg, frange);
fdeg := fdeg-4; { set resolution +/- 3 }
index := 4;
WHILE (index > 0) AND (scan(fdeg, 1) = 0) DO
BEGIN
fdeg := fdeg+3;
index := index-1;
END;
frange := scan(fdeg, 5);
IF (frange > 0) THEN {didn't lose him }
BEGIN
IF (frange > 40) AND (frange < 800) THEN { good shooting range }
cannon(fdeg, frange);
fdeg := fdeg-1; { set resolution +/- 0 }
index := 3;
WHILE (index > 0) AND (scan(fdeg, 0) = 0) DO
BEGIN
fdeg := fdeg+1;
index := index-1;
END;
frange := scan(fdeg, 5);
IF (frange > 0) THEN {didn't lose him }
BEGIN
IF (frange > 40) AND (frange < 800) THEN { good shooting range }
BEGIN
cannon(fdeg, frange);
cannon(fdeg, frange);
END;
course := fdeg;
END;
END;
END;
END;
PROCEDURE chkloc;
{ redirect robot to new degree if it is nearing a wall }
BEGIN
IF (loc_x < 300) THEN { left side }
BEGIN
IF (loc_y < 300) THEN { bottom left }
degree := 45
ELSE
BEGIN
IF (loc_y > 700) THEN { top left }
degree := 315
ELSE
degree := 0;
END;
END
ELSE IF (loc_x > 700) THEN { right side }
BEGIN
IF (loc_y < 300) THEN { bottom right }
degree := 125
ELSE
BEGIN
IF (loc_y > 700) THEN { top right }
degree := 225
ELSE
degree := 180;
END;
END;
IF (loc_y < 300) THEN { bottom side }
BEGIN
IF (loc_x < 300) THEN
degree := 45
ELSE
BEGIN
IF (loc_x > 700) THEN
degree := 125
ELSE
degree := 90;
END;
END
ELSE IF (loc_y > 700) THEN { top side }
BEGIN
IF (loc_x < 300) THEN
degree := 315
ELSE
BEGIN
IF (loc_x > 700) THEN
degree := 225
ELSE
degree := 270;
END;
END;
END; {chkloc}
BEGIN {Marvin Main}
res := 10; { scan resolotion }
degree := 180; { initialize degree }
srdegree := degree; { initialize cannon }
chkloc; { out of bounds ? }
WHILE True DO {Loop Forever}
BEGIN
old_dam := damage;
WHILE (old_dam = damage) DO
BEGIN
chkloc; { out of bounds ? }
drive(degree, 100);
course := srdegree; { set fire direction to current scan }
WHILE (scan(srdegree, res) > 0) AND (old_dam = damage) DO
BEGIN
Range := scan(srdegree, res); { shoot while you can }
IF (Range > 40) AND (Range < 800) THEN { good shooting range }
BEGIN
hitem;
srdegree := course;
END;
chkloc; { change direction if necessary }
drive(degree, 100);
END;
srdegree := srdegree-20; { next degree to scan }
END;
degree := degree-90; { try again }
END;
END; { end of Marvin Main }